﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using SMS.cntr;
using SMS.dao;
using SMS.util;

namespace SMS.view
{
    public partial class ListOfClassesForm : Form
    {
        public ListOfClassesForm()
        {
            InitializeComponent();
        }

        private void bindGridViewList()
        {
            gridViewList.Rows.Clear();

            if (cbClazz.SelectedIndex >= 0)
            {
                DataTable table = StudentCntr.Instance.findStudents(cbClazz.SelectedValue.ToString());
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    gridViewList.Rows.Add(i + 1,
                                            table.Rows[i]["stu_id"].ToString(),
                                            table.Rows[i]["stu_fullname"].ToString(),
                                            table.Rows[i]["gender"].ToString(),
                                            table.Rows[i]["dob"].ToString(),
                                            table.Rows[i]["stu_address"].ToString());
                    gridViewList.Rows[gridViewList.RowCount - 1].Tag = table.Rows[i];
                }
            }
            gridViewList.ClearSelection();       
        }

        private void bindCbClazz()
        {
            cbClazz.DataSource = ClazzCntr.Instance.listAll();
            cbClazz.DisplayMember = "cla_name";
            cbClazz.ValueMember = "cla_id";            
        }

        private void cbClazz_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindGridViewList();            
            txtCapacity.Text = gridViewList.RowCount.ToString(); 
        }

        private void ClassAllStudent_Load(object sender, EventArgs e)
        {
            bindCbClazz();
            bindGridViewList();
            txtCapacity.Text = gridViewList.RowCount.ToString();
            changeLang(I18nUtil.vnLang);
        }

        public void changeLang(String lang)
        {
            I18nUtil.init(lang, new ResourceManager(I18nUtil.resourcePath, typeof(ListOfClassesForm).Assembly));

            this.Text = I18nUtil.getString("listOfClasses");
            label1.Text = I18nUtil.getString("lblClass");
            label2.Text = I18nUtil.getString("lblClassCapacity");
            groupBox1.Text = I18nUtil.getString("gbStudentList");
            gridViewList.Columns[0].HeaderText = I18nUtil.getString("no");
            gridViewList.Columns[2].HeaderText = I18nUtil.getString("fullName");
            gridViewList.Columns[3].HeaderText = I18nUtil.getString("gender");
            gridViewList.Columns[4].HeaderText = I18nUtil.getString("DTB");
            gridViewList.Columns[5].HeaderText = I18nUtil.getString("address");
        }

    }
}
